﻿//************************************************************************************************************
//文件名称(File Name)：CommonMana.cs
//功能描述(Description)：公共管理类
//数据表(Tables)：
//作者(Author)：
//日期(Create Date)：20130302
//参考文档(Reference)(可选)：
//引用(Using) (可选)﹕
//************************************************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DbAdapter.sqldbAdapter;

namespace AnalyseCrmMana
{
    public class CommonMana
    {
        public int AddNewDownlistItem(string selvalue,string memo)
        {
            string sql = "if NOT Exists(select * from tbt_downlist where SELVALUE = '"+selvalue+"') "
                        + "insert into tbt_downlist(SELParent,SELID,SELVALUE,Memo) values('3','" + GetMaxSelID() + "','"
                        + selvalue + "','" + memo + "')";
            sqldb db = new sqldb();
            return db.ExecuteNonQuery(sqlconn.GetConnStr(), CommandType.Text, sql);            
        }

        private string GetMaxSelID()
        {
            string sql = "select SELID from tbt_downlist where SELparent = '3'";
            sqldb db = new sqldb();
            object selid = db.ExecuteScalar(sqlconn.GetConnStr(), CommandType.Text, sql);
            if (selid == null)
            {
                selid = "1";
            }
            else
            {
                selid = Convert.ToInt32(selid) + 1;
            }
            return selid.ToString();
        }
    }
}
